package grpcserver

import (
	"context"
	pb "gitee.com/go-caipu-team/go-caipu-plugin-sdk/genproto/pluginmain"
	"github.com/goccy/go-json"
	user "go-caipu/pkg/services/admin/sysuser"
)

var (
	GetUserByRoleCommand = "getUserByRole"
)

func (as *adminServer) query(ctx context.Context, query queryModel) pb.DataResponse {
	var item pb.DataResponse
	switch query.Command {
	case GetUserByRoleCommand:
		var roleIds []string
		_ = json.Unmarshal(query.Body, &roleIds)
		result, err := as.userService.GetUserByWhere(ctx, user.GetUserRequest{RoleIds: roleIds})
		if err != nil {
			as.logger.Error("query:%s ", query.Command, "err", err)
			item.Error = err.Error()
			return item
		}
		item.JsonData, _ = json.Marshal(result)
		item.Status = 200
	default:
		as.logger.Error("query:%s ", query.Command, "err", "not implemented")
	}
	return item
}
